/**
  ETFDAQ Project
  \class TACrate
  \brief A VME Crate holding a controller, and multiple plugin modules
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2024-08-12
  \date 2024-08-12 last modified

  \copyright Copyright (c) 2024 IMP-CAS with LGPLv3 LICENSE
*/

#ifndef TACrate_h
#define TACrate_h

class TAController;
class TACard;
class TAYaml;
struct event_t;

class TACrate{
public:
  TACrate(TAController *ctl, const TAYaml *cfg, int id = 0);
  virtual ~TACrate();

  virtual void Initialize();
  void SetDebug(bool opt = true);
  virtual void AddCard(const TAYaml &c);
  virtual void AddCard(TACard *c);
  /// \retval -1 to indicate error, else return 0
  virtual int ReadEvent(event_t *ev); ///< module buffer => controller buffer
  virtual void ClearData(); ///< module buffer => controller buffer
  virtual void ClearEventCounter(); ///< SR for all the cards
  virtual void ResetForNewRun();

  int ID() const{ return fId; }
  TAController *GetController() const{ return fController; }
  TACard *GetCard(int slot) const;
  const TAYaml *GetConfig() const{ return fConfig; }
  virtual void Print() const;

  static const int NSLOT = 24;

protected:
  int fId;
  TAController *fController;
  TACard *fCards[NSLOT]; // [slotId]
  const TAYaml *fConfig; ///< the user input
  bool fDebug;
};

#endif
